package com.makingTeam.config.disruptor;

import com.lmax.disruptor.EventTranslatorOneArg;
import com.lmax.disruptor.RingBuffer;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 事件转换器(简化生产者发送信息时操作)
 * user: pzy
 * date: 2025/4/29 11:51
 */
@Component
@RequiredArgsConstructor
public class DisEventTranslator {

    private final RingBuffer<MessageModel> ringBuffer;

    private static final EventTranslatorOneArg<MessageModel, String> TRANSLATOR = (event, sequence, data) -> event.setMessage(data);

    /**
     * 信息发送
     * @param data 数据
     */
    public void onData(String data){
        ringBuffer.publishEvent(TRANSLATOR,data);
    }

}
